package com.github.aloxc.plugin.restplus.test.impl;


import com.github.aloxc.plugin.restplus.test.RestClientResponse;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.entity.ContentType;
import org.jetbrains.annotations.NotNull;
/**
 * @author leero
 */
public class RestClientResponseImpl implements RestClientResponse {
    private final HttpResponse myResponse;
    private final String myContent;

    public RestClientResponseImpl(@NotNull HttpResponse response, @NotNull String content) {
        this.myResponse = response;
        this.myContent = content;
    }


    @NotNull
    public static RestClientResponse createResponse(@NotNull HttpResponse response, @NotNull StringBuffer contentBuffer) {
        return new RestClientResponseImpl(response, contentBuffer.toString());
    }

    @Override
    @NotNull
    public ContentType getContentType() {
        return ContentType.getOrDefault(this.myResponse.getEntity());
    }


    @Override
    @NotNull
    public StatusLine getStatusLine() {
        return this.myResponse.getStatusLine();
    }


    @Override
    @NotNull
    public Header[] getAllHeaders() {
        return this.myResponse.getAllHeaders();
    }


    @Override
    @NotNull
    public String getContent() {
        return this.myContent;
    }


    @Override
    public int getContentLength() {
        return this.myContent.length();
    }
}